/**
 * Created by Administrator on 2018/6/25 0025.
 */

$(function () {
    $('#dgg').datagrid(
        {
            iconCls: 'icon-edit',
            singleSelect: false,
            toolbar: '#tb1',
            title: '编辑商品',
            onDblClickRow: onClickRow,
            columns: [[
                {
                    field: 'id',
                    title: '入库id',
                    checkbox: true,
                    align: 'center'
                }, {
                    field: 'productionId',
                    title: '款号id',
                    align: 'right',
                    hidden: true,
                    width: 90
                }, {
                    field: 'product',
                    title: '商品款号',
                    align: 'center',
                    width: 90
                }, {
                    field: 'productName',
                    title: '商品名称',
                    align: 'center',
                    width: 120,
                }, {
                    field: 'color',
                    title: '颜色',
                    align: 'center',
                    width: 90
                }, {
                    field: 'size',
                    title: '尺码',
                    align: 'center',
                    width: 90
                }, {
                    field: 'shuliang',
                    title: '数量/件',
                    editor: {
                        type: 'validatebox',
                        options: {
                            required: true,
                            validType: 'INTE'
                        }
                    },
                    width: 90,
                    align: 'right'
                }, {
                    field: 'kerushuliang',
                    title: '可退数量',
                    align: 'center',
                    width: 120,
                    hidden: 'true'
                }, {
                    field: 'price',
                    title: '铭牌价/￥',
                    align: 'right',
                    width: 90,
                    formatter: function (value, row, index) {
                        value = value - 0;
                        return value.toFixed(2)
                    }
                }, {
                    field: 'chengbenjia',
                    title: '成本价/￥',
                    align: 'right',
                    formatter: function (value, row, index) {
                        value = parseFloat(value)
                        return Math.abs(value.toFixed(2))
                    }
                }, {
                    field: 'zongjia',
                    title: '总价/￥',
                    align: 'right',
                    width: 90,
                    formatter: function (value, row, index) {
                        return Math.abs(row.chengbenjia * parseInt(row.shuliang)).toFixed(2)
                    }
                }
            ]]
        })
})


$.extend($.fn.validatebox.defaults.rules, {
    INT: {
        validator: function (value) {
            if (/^[+]?[1-9]+\d*$/i.test(value)) {

                if ($(this).attr('placeholder') != '' && $(this).attr('placeholder') != null) {
                    if (value <= parseInt($(this).attr('placeholder'))) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return true;
                }
            } else {
                return false;
            }
        },
        message: '必须是整数/不能超过输入框提示数量'
    },
    YZ: {
        validator: function (value) {
            if (!/^[+]?[0-9]+\d*$/i.test(value)) {
                return false;
            }
            value = value - 0;
            var sum = ($("#sp table td").length / $("#sp table tr").length - 1) - 1
            if (value % sum == 0) {
                return true;
            } else {
                return false;
            }
        },
        message: '请输入尺码数量的倍数'
    },
    INTE: {
        validator: function (value) {
            if (/^[+]?[1-9]+\d*$/i.test(value)) {
                if ($('#dgg').datagrid("getSelected").kerushuliang != null && $('#dgg').datagrid("getSelected").kerushuliang != '') {
                    if (parseInt($('#dgg').datagrid("getSelected").kerushuliang) != 0) {
                        if (parseInt($('#dgg').datagrid("getSelected").kerushuliang) >= value) {
                            return true;
                        } else {
                            return false;
                        }
                    } else {
                        return true
                    }
                } else {
                    return true;
                }
            } else {
                return false;
            }
        },
        message: "必须是整数或已超出实际数量"
    },
    ZS: {
        validator: function (value) {
            if (value != 0 && value != null && value != '') {
                return true;
            } else {
                return false;
            }
        },
        message: "请输入大于零的数"
    }
});
var records;
function loadRukudan(parms, gongyingshangid) {
    $("#rukudan").combogrid({
            panelWidth: 550,
            width: 150,
            fitColumns: true,
            height: 25,
            idField: 'id',
            textField: 'product',
            mode: 'remote',
            url: path + '/ruku/rukudan/product.do?id=' + $("#id").val() + '&rukuleixing=' + parms + '&gongyingshangid=' + gongyingshangid,
            columns: [[
                {field: 'id', title: '入库Id', hidden: 'true'},
                {field: 'rukudanhao', title: '入库单号'},
                {field: 'product', title: '商品款号'},
                {field: 'zongshuliang', title: '总数量'},
                {field: 'zongjia', title: '总价'},
                {field: 'rukushijian', title: '入库时间'}
            ]],
            onSelect: function (rowIndex, rowData) {
                sid = rowData.id
            },
            onHidePanel: function () {
                if ($('#rukudan').combogrid('grid').datagrid('getSelected') != null) {
                    loadcombobox(sid);
                    $("#dgg").datagrid("loadData", {rows: []});
                    $("#zongjianshu").text("");
                    $("#zongjia").text("0");
                    $('#se').next('span').find('input').focus();
                    $("#se").combobox("showPanel");
                }
            }
        }
    )
}
//加载combobox
function loadcombobox(id) {
    $("#se").combobox({
        url: path + '/ruku/findproduct.do?id=' + id,
        valueField: 'id',
        textField: 'product',
        editable: true,
        width: 150,
        height: 25,
        onSelect: function (data) {
            records = data;
        },
        onHidePanel: function () {
            if ($("#se").combobox("getValue") != null && $("#se").combobox("getValue") != "") {
                //根据入库id和款号id去查询颜色尺码以及数量
                $.ajax({
                    url: path + "/ruku/details.do",
                    data: {
                        id: id,
                        product: records.product,
                        rukuId: $("#id").val()
                    },
                    dataType: 'json',
                    success: function (data) {
                        //拼接
                        var colors = data.rows.color
                        var sizes = data.rows.size
                        var data = data.data;
                        var table = "<table><tr><td class='size'></td>"
                        for (var i = 0; i < sizes.length; i++) {
                            table += "<td class='size'>" + sizes[i] + "</td>"
                        }
                        table += '<td>总计</td></tr>'
                        for (var i = 0; i < colors.length; i++) {
                            table += "<tr><td>" + colors[i] + "</td>"
                            for (var j = 0; j < sizes.length; j++) {
                                table += "<td><input name='shuliang'  class='easyui-validatebox cs'  onkeyup='diaoyong(this)' validType='INT' style='width:50px;border-radius:5px'"
                                for (var z = 0; z < data.length; z++) {
                                    if (sizes[j] == data[z].size) {
                                        if (data[z].color == colors[i]) {
                                            table += " placeholder=" + data[z].shuliang + "";
                                            break;
                                        }
                                    }
                                }
                                table += " placeholder=0></td>"
                            }
                            table += "<td><input name='shuliang' class='easyui-validatebox'  onkeyup='diaoyong1(this)' validType='YZ' style='width:50px;border-radius:5px'></td>"
                            table += "</tr>"
                        }
                        table += "</table>";
                        $('#sp').empty();
                        $('#sp').append(table)
                        $.parser.parse($("#sp"));
                        $('#cc').combo('showPanel');
                        //聚焦到第一个输入框
                        $("#sp table").find("tr").eq(1).find("td").eq(1).children().focus();
                        flg = false;
                    }
                })
            }
        }
    })

}

var canshu;
// 树默认选中
$(function () {
    //加载树
    findTree();
    var addr_tree = $("#tree").combotree({
        onSelect: function (node) {
            load(node.id);
        },
        onLoadSuccess: function (node, data) {
            $("#tree").combotree('setValue', data[0].id);
            $("#dg").datagrid({
                url: path + '/ruku/list.do',
                queryParams: {
                    jgId: data[0].id,
                    state: 0,
                    state2: 1,
                    state3: -1,
                    fenlei: 1
                }
            });
        }
    });

    $("#gys").combotree({
        onLoadSuccess: function (node, data) {
            $("#gys").combotree('setValue', data[0].id);
        }
    });


    //新增combobox选中事件
    $("#leixing").combobox({
        onSelect: function (value) {
            $("#dgg").datagrid("loadData", {rows: []});
            //loadRukudan(value.value);
            if ($("#jgid").val() == 1 || value.value == 1) {
                $("#gongyingshang").combobox({
                    url: path + "/gongyingshang/combobox/leixing.do?leixing=" + value.value,
                    valueField: 'id',
                    textField: 'gname',
                    editable: false,
                    width: 150,
                    height: 25,
                    onLoadSuccess: function (data) {
                        if (canshu != null && canshu != "") {
                            $("#gongyingshang").combobox("setValue", canshu);
                        } else {
                            if (data != null && data != "") {
                                $("#gongyingshang").combobox('setValue', data[0].id);
                            }
                        }
                        canshu = "";
                    },
                    onSelect: function (data) {
                        loadRukudan(value.value, data.id);
                        $("#se").combobox("loadData", []);
                    }
                });
                $("#gongyingshang").next(".combo").show();
                $("#gys").next(".combo").hide();
            } else {
                $("#gongyingshang").next(".combo").hide();
                $("#gys").next(".combo").show();
            }
        }
    })
})


//加载数据
function load(parmjgId) {
    var jgId = "";
    if (parmjgId != null && parmjgId != "") {
        jgId = parmjgId;
    } else {
        jgId = $("#tree").combotree('getValue');
    }
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    // 判断日期有效性
    startDate = startTime.replace("-", "/");//替换字符，变成标准格式
    endDate = endTime.replace("-", "/");//替换字符，变成标准格式
    var d1 = new Date(Date.parse(startDate));
    var d2 = new Date(Date.parse(endDate));
    if (d1 > d2) {
        $.messager.alert('提示', '开始日期不能大于结束日期');
        return;
    }

    $("#dg").datagrid({
        url: path + '/ruku/list.do',
        queryParams: {
            jgId: jgId,
            rukuleixing: $("#search").searchbox("getName"),
            rukudanhao: $("#search").searchbox("getValue"),
            state: $("#caogao:checked").val(),
            state2: $("#dairuku:checked").val(),
            state3: $("#yiruku:checked").val(),
            startTime: startTime,
            endTime: endTime,
            fenlei: 1
        }
    });
}
//提交
function tijiao() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        if (row.state != 0) {
            $.messager.alert('提示', '新单状态下才可提交，请确认数据重试');
            return;
        }
        $.messager.confirm('提示', '是否确认提交' + row.rukudanhao + '?', function (r) {
            if (r) {
                $.ajax({
                    url: path + "/ruku/tijiao.do",
                    data: {
                        id: row.id
                    },
                    dataType: 'json',
                    beforeSend: function () {
                        $("#shenhe").linkbutton('disable');
                    },
                    complete: function () {
                        $("#shenhe").linkbutton('enable');
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            $.messager.show({
                                title: '提示',
                                msg: '提交成功',
                                timeout: 3000,
                                showType: 'slide'
                            });
                            //重新加载
                            //value是搜索框里的值,name是选择框里的值
                            load();
                        } else {
                            $.messager.alert('提示', data.msg);
                            load();
                        }
                    }
                })
            }
        })
    } else {
        $.messager.alert('提示', '请选中要提交的数据');
    }

}
//打开窗口
function winOpen(parm) {

    clear();

    //parm==0是新增parm==1是修改
    if (parm == 0) {
        $("#leixing").combobox("select", "0");
        loadRukudan(0);
        $('#windowadd').dialog({title: "新增入库退货单"});
        $("#windowadd").window("open");
        $('#rukudanhao').textbox("setValue", "RK" + Date.parse(new Date()) + '' + Math.round(Math.random() * 9 + 1));
    } else {
        $('#windowadd').dialog({title: "修改入库退货单"});
        var row = $('#dg').datagrid('getSelected');
        if (row.state != 0) {
            $.messager.alert('提示', '新单状态下才可修改');
            return;
        }
        $.ajax({
            url: path + "/ruku/findxiugaitui/id.do",
            data: {
                id: row.id
            },
            dataType: 'json',
            success: function (data) {
                if (data.code == 200) {
                    canshu = data.data[0].gongyingshangid
                    $("#id").val(row.id);
                    $("#rukudanhao").textbox("setValue", (row.rukudanhao));
                    $("#leixing").combobox("select", data.data[0].leixing);
                    $("#gongyingshang").combobox("setValue", data.data[0].gongyingshangid);
                    loadRukudan(data.data[0].leixing);
                    $("#rukudan").combogrid('setValue', data.data[0].rukuId);
                    loadcombobox(data.data[0].rukuId);
                    $("#dgg").datagrid("loadData", data.data);
                    zongjia();
                } else {
                    $.messager.alert('提示', data.msg);
                }
            }
        })
    }
    $("#windowadd").window("open");
}
//编辑保存
function accept() {
    var flag = true;
    //alert(r.productName);//随便 点出行内各个字段属性值
    if (endEditing()) {
        if (shu()) {
            for (var i = 1; i < $("#sp table tr").length; i++) {
                for (var j = 1; j < $("#sp table td").length / $("#sp table tr").length - 1; j++) {
                    if ($("#sp table").find("tr").eq(i).find("td").eq(j).children().val() == '' || $("#sp table").find("tr").eq(i).find("td").eq(j).children().val() == 0) {
                        continue;
                    }
                    var g = $('#rukudan').combogrid('grid');	// 获取表格控件对象
                    var r = g.datagrid('getSelected');	//获取表格当前选中行
                    $('#dgg').datagrid('appendRow',
                        {
                            shuliang: $("#sp table").find("tr").eq(i).find("td").eq(j).children().val(),
                            color: $("#sp table").find("tr").eq(i).find("td").eq(0).text(),
                            size: $("#sp table").find("tr").eq(0).find(".size").eq(j).text(),
                            chengbenjia: records.chengbenjia,
                            product: records.product,
                            price: records.price,
                            productName: records.productName,
                            id: r.id,//入库id
                            productionId: records.id,
                            kerushuliang: $("#sp table").find("tr").eq(i).find("td").eq(j).children().attr('placeholder')
                        });
                    $("#se").next('span').find('input').focus()// 聚焦到combobox
                }
            }
            var count = $('#dgg').datagrid('getRows').length
            $('#count span').empty();
            $('#count span').text(count);
            $('#se').combobox('setValue', '')
            $('#sp').empty();
            $('#dgg').datagrid('acceptChanges');
            $('#dgg').datagrid('clearSelections');
            zongjia()
            $("#sp table input").val('')
            flag = false;
            iq = 1
            flg = false// //解决enter键第一次冲突问题
            $('#cc').combo('hidePanel');
        }

        if (flag) {

            var drow = $('#dgg').datagrid('getSelections')
            for (var i = 0; i < drow.length; i++) {
                var index = $('#dgg').datagrid(
                    'getRowIndex', drow[i]);
                $('#dgg').datagrid('beginEdit', index);

                drow[i].zongjia = (parseFloat(drow[i].chengbenjia) * parseInt(drow[i].shuliang))

                $('#dgg').datagrid('endEdit', index);
            }
        }
        zongjia()
        f = false;
    }
}
//保存入库退货
function saveRuku() {
    if (!endEditing()) {
        return;
    }
    var rows = $("#dgg").datagrid("getRows");
    var a = 0;
    var zongjia = 0;
    var zongjianshu = 0;
    var shuliang = 0;
    var danjia = 0;
    var ruku = '[';
    for (var i = 0; i < rows.length; i++) {
        shuliang = rows[i].shuliang - 0;
        danjia = rows[i].chengbenjia - 0;
        zongjia += shuliang * danjia;
        zongjianshu += rows[i].shuliang - 0;
    }
    if (zongjia != $('#zongjia').text() && zongjianshu != $('#zongjianshu').text()) {
        $.messager.alert("提示", '编辑数据出现异常,请检查编辑内容!')
        retrun;
    }
    var rows = $("#dgg").datagrid("getRows");
    if (rows != '') {
        for (var i = 0; i < rows.length; i++) {
            if (i == rows.length - 1) {
                ruku += "{'shuliang':'" + rows[i].shuliang + "','color':'" + rows[i].color + "','productionId':'" + rows[i].productionId + "','size':'" + rows[i].size + "','danjia':'" + rows[i].chengbenjia + "'}]"
                break;
            }
            ruku += "{'shuliang':'" + rows[i].shuliang + "','color':'" + rows[i].color + "','productionId':'" + rows[i].productionId + "','size':'" + rows[i].size + "','danjia':'" + rows[i].chengbenjia + "'},"
        }
        var gongyingshang = '';
        if ($("#jgid").val() == 1) {
            gongyingshang = $("#gongyingshang").combobox('getValue');
        } else if ($("#jgid").val() != 1 && $("#leixing").combobox('getValue') == 0) {
            gongyingshang = $("#gys").combotree('getValue');
        } else {
            gongyingshang = $("#gongyingshang").combobox('getValue');
        }
        $('#save').linkbutton('disable');
        var g = $('#rukudan').combogrid('grid');	// 获取表格控件对象
        var r = g.datagrid('getSelected');	//获取表格当前选中行
        $.ajax({
            url: path + '/ruku/savetui.do',
            type: 'post',
            data: {
                id: $("#id").val(),
                ruku: ruku,
                rukuleixing: $("#leixing").combobox('getValue'), // 入库类型
                rukudanhao: $('#rukudanhao').val(),// 入库单号
                gongyingshangid: gongyingshang,
                fenlei: 1,//0进货1是退货
                rukuId: r.id
            },
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    $.messager.show({
                        title: '提示',
                        msg: '添加成功！',
                        timeout: 4000,
                        showType: 'slide'
                    })
                    load()
                    $('#windowadd').window('close');
                    $('#cc').combo('hidePanel');
                    $('#save').linkbutton('enable');
                } else {
                    $.messager.alert("提示", data.msg);
                }
            }, complete: function (XMLHttpRequest, status) { // 请求完成后最终执行参数
                if (status == 'timeout') {// 超时,status还有success,error等值的情况
                    ajaxTimeoutTest.abort();
                    $.messager.show({
                        title: '提示',
                        msg: '请求超时！',
                        timeout: 1000,
                        showType: 'slide'
                    });
                }
                $('#save').linkbutton('enable');
            }
        })
    } else {
        $.messager.alert("提示", '编辑栏为空，不能保存!')
    }
}


function shu() {
    for (var i = 1; i < $("#sp table tr").length; i++) {
        for (var j = 1; j < $("#sp table td").length / $("#sp table tr").length - 1; j++) {
            if ($("#sp table").find("tr").eq(i).find("td").eq(j).children().val() != '' && $("#sp table").find("tr").eq(i).find("td").eq(j).children().val() != 0) {
                if (!/^[+]?[1-9]+\d*$/.test($("#sp table").find("tr").eq(i).find("td").eq(j).children().val())) {
                    $('#cc').combo('showPanel')
                    $("#sp table").find("tr").eq(i).find("td").eq(j).children().focus()
                    return false;
                }
                if ($("#sp table").find("tr").eq(i).find("td").eq(j).children().attr('placeholder') != '')
                    if (parseInt($("#sp table").find("tr").eq(i).find("td").eq(j).children().attr('placeholder')) < $("#sp table").find("tr").eq(i).find("td").eq(j).children().val()) {
                        $('#cc').combo('showPanel')
                        $("#sp table").find("tr").eq(i).find("td").eq(j).children().focus()
                        return false;
                    }
            }
        }
    }
    if ($("#sp table td").length == 0) {
        return false
    }
    if ($('#dgg').datagrid('getRows').length != 0) {
        var r;
        if ($("#leixing").combobox("getValue") == 0) {
            var g = $('#rukudan').combogrid('grid');	// 获取表格控件对象
            r = g.datagrid('getSelected');	//获取表格当前选中行
        } else {
            r = records;
        }

        for (var i = 0; i < $('#dgg').datagrid('getRows').length; i++) {

            // if (r.product == $('#dgg').datagrid('getData').rows[i].product) {

            for (var j = 1; j < $("#sp table tr").length; j++) {
                for (var z = 1; z < $("#sp table td").length / $("#sp table tr").length - 1; z++) {
                    if ($("#sp table").find("tr").eq(j).find("td").eq(z).children().val() != '') {
                        if ($("#sp table").find("tr").eq(j).find("td").eq(0).text() == $('#dgg').datagrid('getData').rows[i].color) {
                            if ($("#sp table").find("tr").eq(0).find(".size").eq(z).text() == $('#dgg').datagrid('getData').rows[i].size) {
                                $('#cc').combo('hidePanel');
                                $('#sp').empty();
                                doSearch(r.product)
                                $.messager.alert("提示 ", r.product + ":" + $("#sp table").find("tr").eq(j).find("td").eq(0).text() + ":" + $("#sp table").find("tr").eq(0).find(".size").eq(z).text() + '已添加')
                                return false;
                            }
                        }
                    }
                }
                // }
            }
        }
    }
    return true;
}

var editIndex = undefined;
function endEditing() {
    if (editIndex == undefined) {
        return true
    }
    if ($('#dgg').datagrid('validateRow', editIndex)) {
        $('#dgg').datagrid('endEdit', editIndex);
        editIndex = undefined;
        return true;
    } else {
        return false;
    }
}
//清空
function clear() {
    $("#dgg").datagrid("loadData", {rows: []});
    $("#zongjianshu").text("0");
    $("#zongjia").text("0");
    $("#se").combobox("loadData", []);
    $("#se").combobox("setValue", '');

    //$("#rukudan").combogrid('setValue', '');

    $('#sp').empty();
    $("#id").val("");

}
//删除新增
function removeit() {
    var selRow = $('#dgg').datagrid('getSelections')
    if (selRow == 0) {
        $.messager.alert("提示", '请选择要删除的行');
        return
    } else {
        $.messager.confirm('提示信息', '真的要执行删除操作', function (r) {
            if (r) {
                for (var i = 0; i < selRow.length; i++) {
                    var index = $('#dgg').datagrid(
                        'getRowIndex', selRow[i]);
                    $('#dgg').datagrid('cancelEdit', editIndex)
                        .datagrid('deleteRow', index);
                    zongjia();
                    f = false;
                    var count = $('#dgg').datagrid('getRows').length
                    $('#count span').empty();
                    $('#count span').text(count);
                    editIndex = undefined;
                }
            }
        })
    }
}
//计算总价
function zongjia() {
    var rows = $("#dgg").datagrid("getRows");
    var zongjia = 0;
    var zongjianshu = 0;
    for (var i = 0; i < rows.length; i++) {
        zongjia += (rows[i].shuliang - 0) * (rows[i].chengbenjia - 0);
        zongjianshu += rows[i].shuliang - 0;
    }
    $('#zongjia').text(zongjia.toFixed(2));
    $('#zongjianshu').text(zongjianshu);
}

var f = false;
function onClickRow(index) {
    if (editIndex != index) {
        // 点击修改总价
        if (f) {
            $('#dgg').datagrid('endEdit', editIndex);
            var drow1 = $('#dgg').datagrid('getData').rows[editIndex];
            var dan;
            var i = editIndex
            dan = drow1.chengbenjia
            dab = drow1.shuliang
            $('#dgg').datagrid('beginEdit', editIndex);
            $('#dgg').datagrid('getRows')[i]['zongjia'] = (dan * parseInt(drow1.shuliang)).toFixed(2);
            zongjia()
        }
        if (endEditing()) {
            $('#dgg').datagrid('clearSelections');
            $('#dgg').datagrid('selectRow', index).datagrid('beginEdit', index);
            f = true
            editIndex = index;
        } else {
            $('#dgg').datagrid('selectRow', editIndex);
        }
    }
}
//入库
function ruku() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        if (row.state != 1) {
            $.messager.alert('提示', '待入库状态下才可提交，请确认数据重试');
            return;
        }
        $.messager.confirm('提示', '是否确认提交' + row.rukudanhao + '?', function (r) {
            if (r) {
                $.ajax({
                    url: path + "/ruku/tuihuo.do",
                    data: {
                        id: row.id
                    },
                    dataType: 'json',
                    beforeSend: function () {
                        $("#rukuspan").linkbutton('disable');
                    },
                    complete: function () {
                        $("#rukuspan").linkbutton('enable');
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            $.messager.show({
                                title: '提示',
                                msg: '提交成功',
                                timeout: 3000,
                                showType: 'slide'
                            });
                            //重新加载
                            //value是搜索框里的值,name是选择框里的值
                            load();
                        } else {
                            $.messager.alert('提示', data.msg);
                            load();
                        }
                    }
                })
            }
        })
    } else {
        $.messager.alert('提示', '请选中要提交的数据');
    }
}
//删除入库单
function shanchu() {
    var row = $('#dg').datagrid('getSelected');
    if (row.state != 0) {
        $.messager.alert('提示', '新单状态才可删除');
        return;
    }
    if (row) {
        $.messager.confirm('提示', '是否确认删除' + row.rukudanhao + '?', function (r) {
            if (r) {
                $.ajax({
                    url: path + '/ruku/del/id.do',
                    dataType: 'json',
                    type: 'POST',
                    data: {
                        id: row.id
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            $.messager.show({
                                title: '提示',
                                msg: "删除" + row.rukudanhao + '成功!',
                                timeout: 3000,
                                showType: 'slide'
                            });
                            load();
                        } else {
                            $.messager.alert('提示', data.msg);
                        }
                    }
                })
            }
        });
    } else {
        $.messager.alert('提示', '请选择要操作的数据');
    }
}
//驳回
function bohui() {
    var row = $('#dg').datagrid('getSelected');
    if (row.state != 1) {
        $.messager.alert('提示', '待入库状态才可驳回');
        return;
    }
    if (row) {
        $.messager.confirm('提示', '是否确认驳回' + row.rukudanhao + '?', function (r) {
            if (r) {
                $.ajax({
                    url: path + '/ruku/bohui/id.do',
                    dataType: 'json',
                    type: 'POST',
                    data: {
                        id: row.id
                    },
                    beforeSend: function () {
                        $("#shenhe2").linkbutton('disable');
                    },
                    complete: function () {
                        $("#shenhe2").linkbutton('enable');
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            $.messager.show({
                                title: '提示',
                                msg: "驳回" + row.rukudanhao + '成功!',
                                timeout: 3000,
                                showType: 'slide'
                            });
                            load();
                        } else {
                            $.messager.alert('提示', data.msg);
                        }
                    }
                })
            }
        });
    } else {
        $.messager.alert('提示', '请选择要操作的数据');
    }
}